<?php

class RevisionArticle extends CActiveRecord
{
	

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_articles_revision';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(

		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'articles' => array(self::BELONGS_TO, 'Article', 'p_id'),
			'users' => array(self::BELONGS_TO, 'User', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'content' => 'Comment',
			'status' => 'Status',
			'created' => 'Create Time',
			'author' => 'Name',
			'email' => 'Email',
			'url' => 'Website',
			'article_id' => 'Article',
			'user_id' => 'User',
		);
	}

	public function search() {
		$criteria = new CDbCriteria;

		$criteria->compare('id', $this->id);
		$criteria->compare('article_id', $this->article_id);
		$criteria->compare('content', $this->content, true);
		$criteria->compare('email', $this->email);
		$criteria->compare('created', $this->created, true);
		$criteria->compare('url', $this->url, true);
		$criteria->compare('status', $this->status);
        $criteria->order = 't.created desc';
		/*
		$criteria->compare('articles.title', $this->articles, true, 'OR');
		$criteria->with = array('articles');
		*/
		$criteria->compare('users.username', $this->users, true, 'OR');
		$criteria->with = array('users');
		
		$criteria->together = true;
		
		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
		));
	}
	
}